package travlefate.story.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import travlefate.story.R;
import travlefate.story.utils.Http;

/**
 * @author keven
 * @data 15/12/21 下午5:09
 * @package travlefate.story.adapter
 */

public class StoryListImgAdapter extends BaseAdapter {

    private List<String> mPics = new ArrayList<String>();

    @Override
    public int getCount() {
        return mPics.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.type_item_image, null);
            holder = new ViewHolder();
            holder.imageView = (ImageView) convertView.findViewById(R.id.single_image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Picasso.with(parent.getContext()).load(Http.BASE_UPLOADS+mPics.get(position)).resize(200, 200).centerCrop().into(holder.imageView);

        return convertView;
    }

    public void addDatas(List<String> pics) {
        if (pics != null) {
            this.mPics.clear();
            this.mPics.addAll(pics);
        }
        notifyDataSetChanged();
    }

    class ViewHolder {
        ImageView imageView;
    }
}
